package com.ice.anpa.fragments;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.actionbarsherlock.app.SherlockFragment;
import com.ice.anpa.R;
import com.ice.anpa.activities.DetailNewsActivity;
import com.ice.anpa.adapters.CastrationListAdapter;
import com.ice.anpa.common.Constants;
import com.ice.anpa.domain.Castration;

public class LastCastrationFragment extends SherlockFragment{
	
	private CastrationListAdapter castrationAdapter;
	private ListView lv_castrations;
	
	@Override
	public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
		View view = inflater.inflate(R.layout.fragment_list_castrations, container, false);
		
		lv_castrations = (ListView) view.findViewById(R.id.list_castrations);
		ArrayList<Castration> castrationlist = new ArrayList<Castration>();
		/*Carga los datos de castraciones*/
		castrationlist = loadCastrations();
		
		castrationAdapter = new CastrationListAdapter(getActivity(), castrationlist);
		lv_castrations.setAdapter(castrationAdapter);
		
		lv_castrations.setOnItemClickListener(onclickListCastrations);
		
		//ImageButton btn_news = (ImageButton) view.findViewById(R.id.btn_home_news);
		//btn_news.setOnClickListener(onNewsClick);
		
		return view;
	}
	
	public ArrayList<Castration> loadCastrations (){
		ArrayList<Castration> castrationlist = new ArrayList<Castration>();
		castrationlist.add(new Castration(Long.valueOf(1),"Sabana Sur, Castra", "Castraciones gratis..", "14/02/2014", null));
		castrationlist.add(new Castration(Long.valueOf(2),"Paso Ancho, Castra", "Castraciones gratis...", "14/02/2014", null));
		castrationlist.add(new Castration(Long.valueOf(3),"San Sebas, Castra", "Castraciones gratis..", "14/02/2014", null));
		return castrationlist;
	}
	
	private OnItemClickListener onclickListCastrations = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			// TODO Auto-generated method stub
			Castration castration = (Castration) castrationAdapter.getItem(position);
			Intent intent = new Intent(getActivity(), DetailNewsActivity.class);
			intent.putExtra(Constants.ID_OBJ_DETAIL_CASTRATION, castration);
			startActivity(intent);
			//Toast.makeText(getActivity(), "Entro" + idNews.toString(), Toast.LENGTH_LONG).show();
			
		}
	};
}
